package sudoku;

import java.util.ArrayList;

/** 
 * Class represents single cell on a classic sudoku board. ClassicCell lives independent from
 * grid on which it's placed. In other words, no checks of position validity 
 * is performed inside class.
 *
 * @author Taras Basiuk
 * @version 0.1
 */
public class ClassicCell extends Cell{

    /** 
     * ClassicCell position number on sudoku board in top-most line left-most column
     * board representation. Zero indexing.
     *  0  1  2 |  3  4  5 |  6  7  8
     *  9 10 11 | 12 13 14 | 15 16 17
     * 18 19 20 | 21 22 23 | 24 25 26
     * ---------+----------+----------
     * 27 28 29 | ...
     * 36 37 38 | ...
     * 45 46 47 | ...
     * ---------+ ----
     * ...      | 
     */
    private int rowPosition;

    /** 
     * ClassicCell position number on sudoku board in left-most column top-most line
     * board representation. Zero indexing.
     *  0  9 18 | 27 36 45 | 54 63 72
     *  1 10 19 | 28 37 46 | 55 64 73
     *  2 11 20 | 29 38 47 | 56 65 74
     * ---------+----------+----------
     *  3 12 21 | ...
     *  4 13 22 | ...
     *  5 14 23 | ...
     * ---------+ ----
     * ...      | 
     */
    private int columnPosition;

    /** 
     * ClassicCell position number on sudoku board in next way representation :
     *  0  1  2 |  9 10 11 | 18 19 20
     *  3  4  5 | 12 13 14 | 21 22 23
     *  6  7  8 | 15 16 17 | 24 25 26
     * ---------+----------+----------
     * 27 28 29 | ...
     * 30 31 32 | ...
     * 33 34 35 | ...
     * ---------+ ----
     * ...      | 
     */
    private int squarePosition;
    
    /** 
     * Constructor for cell with given position on the grid and maximum value. 
     * Sets cell to be empty, available to user input,
     * fills possibleValues with range of values from 1 to maxValue. 
     */
    public ClassicCell(int rowN, int colN, int sqrN, int maxV){
        super(maxV);        
        rowPosition = rowN;
        columnPosition = colN;
        squarePosition = sqrN; 
    }   
    
    /** Constructor for cell with given position on the grid, value, userAccess and maximum value. */
    public ClassicCell(int rowN, int colN, int sqrN, int maxV, int value, boolean access){        
        super(maxV, value, access);        
        rowPosition = rowN;
        columnPosition = colN;
        squarePosition = sqrN;
    }

    /** Method returns rowPosition number. */
    public int getRowPosition(){
        return rowPosition;
    }

    /** Method returns columnPosition number. */
    public int getColumnPosition(){
        return columnPosition;
    }

    /** Method returns squarePosition number. */
    public int getSqrPosition(){
        return squarePosition;
    }
    
    /** Method returns valid copy of this cell. */
    @Override
    public ClassicCell clone(){
        
        ClassicCell clone = new ClassicCell(rowPosition, columnPosition, squarePosition, maxValue, value, userAccess);        
        
        if (value == 0){
            for(int i=1; i<=maxValue; i++){
                if (!possibleValues.contains(i)){
                    clone.excludeFromPossibles(i);
                }
            }
        }        
        
        return clone;                
    }
 }
